import { Button } from 'antd';
import React, { useCallback, useRef} from 'react';
import Dio from './c_diolog';
import CTable from './c_table'

const App: React.FC<cType.tableDioProTp> = (prps) => {
  const cdioRef:any=useRef()
  const ctableRef:any=useRef()
  const showModal=(data?:any)=>{
    let datad=data?data:{}
    if(prps.formOption.formOption.initiaData&&!datad.id)datad=prps.formOption.formOption.initiaData
    if(prps.formOption.dioOption.beforeshowModal)prps.formOption.dioOption.beforeshowModal(datad)
    cdioRef.current.showModal(datad)
  }
  const getUserTable=async(data)=>{
    ctableRef.current.getUserTable(data?data:{limit:10,start:1})
  }
  const dioOptoon:cType.dioProTp={
    getUserTable:(data)=>getUserTable(data),
    formOption:prps.formOption
  }
  const tableOptoon:cType.tableProTp={
    showModal:(data:any)=>showModal(data),
    tableOption:prps.tableOption
  }
  return (
    <div>
      <Button type="primary" onClick={showModal}>{prps.btnTitle}</Button>
      <CTable {...tableOptoon} ref={ctableRef} />
      <Dio ref={cdioRef} {...dioOptoon}></Dio>
    </div>
  );
};
export default App;
